package org.example.transform;

import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.StringReader;

public class ByteCharTest {

    /**
     * 将字符流转换为字节流并且输出打印
     *
     * @param args
     */
    public static void main(String[] args) throws Exception {
        //输入字符流
        StringReader stringReader = new StringReader("123");
        char[] charBuf = new char[10];
        //字符流转成字节流必须走 OutputStreamWriter
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("C:/data/1.txt"));
        int readInt = 0;
        while ((readInt = stringReader.read(charBuf)) != -1) {
            osw.write(charBuf, 0, readInt);
        }
        //必须调用flush才能触发os写入磁盘文件
        osw.flush();
        System.out.println("已经写出完毕");
    }
}
